<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <include file="Public:header" />
</head>
<body>
  <include file="Public:body_top" />

  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-md-2 sidebar hidden-xs">
        <div class="menu">
          <dl>
            <dt><i class="cm-order"></i>订单管理</dt>
            <dd><a href="{:U('Orders/index')}">订单列表</a></dd>
            <dd><a href="{:U('Orders/order_count')}">订单统计</a></dd>
            <dd <if condition="$types neq 2"> class="active" </if> ><a href="{:U('Settlements/amount_logs')}">结算记录</a></dd>
            <dd <if condition="$types eq 2"> class="active" </if> ><a href="{:U('Settlements/amount_logs?types=2')}">返利提现记录</a></dd>
          </dl>
        </div>
      </div>
      <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <div class="main-hd">
          <h5>记录列表</h5>
        </div>
        <div class="main-bd">
          <form method="post" action="{:U('Settlements/amount_logs')}" id="myfrom">
            <div class="form-box order-datatime">
              <div class="form-horizontal">
                <div class="form-group">
                  <label class="col-sm-2 control-label">申请时间</label>
                  <div class="col-sm-3 form_datetime">
                    <input class="form-control" id="datetime-start" type="text" placeholder="开始时间" name="beg_time" value="{$beg_time}" id="beg_time" readonly>
                    <!-- <span class="input-group-addon"><i class="cm-calendar"></i></span> -->
                  </div>
                  <label class="col-sm-1 control-label">到</label>
                  <div class="col-sm-3">
                    <input class="form-control" id="datetime-end" type="text" placeholder="结束时间" name="end_time" value="{$end_time}" id="end_time" readonly>
                    <!-- <span class="input-group-addon"><i class="cm-calendar"></i></span> -->
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-sm-2 control-label">店铺名称</label>
                  <div class="col-sm-3">
                    <input class="form-control" name="shop_name" type="text" placeholder="输入店铺名称" value="{$shop_name}">
                  </div>
                </div>
                <div class="form-group">
                  <div class="col-sm-12 col-md-9 form-box-btns">
                    <input type="hidden" name="types" value={$types}>
                    <input id="flag" type="hidden" name="flag" value="">
                    <a class="btn btn-primary" href="#" onClick="inquiry()">查询</a>
                    <a class="btn btn-default" href="#" onClick="flag()">导出</a>
          
                  </div>
                </div>
              </div>
            </div>
          </form>
          <ul class="nav nav-tabs">
            <li class="{$status > 0 ? ''  : 'active'}"><a href="{:U('Settlements/amount_logs?types='.$types)}">全部记录</a></li>
            <li class="{$status == 2 ? 'active'  : ''}"><a href="{:U('Settlements/amount_logs?status=2&types='.$types)}">已申请</a></li>
            <li class="{$status == 3 ? 'active'  : ''}"><a href="{:U('Settlements/amount_logs?status=3&types='.$types)}">已提现</a></li>
            <li class="{$status == 4 ? 'active'  : ''}"><a href="{:U('Settlements/amount_logs?status=4&types='.$types)}">已拒绝</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane active" id="all-order">
              <div class="table-responsive">
                <table class="table table-cmcm">
                  <tr>
                    <th width="250">商户</th>
                    <th>提现金额</th>
                    <th>状态</th>
                    <th>申请类型</th>
                    <th>申请时间</th>
                    <th>打款时间</th>
                    <th>操作</th>
                  </tr>
                  <volist name="page_list.list" id="vo">
                    <tr>
                      <td>{$vo.shop_name}</td>
                      <td>{$vo.amount}</td>
                      <td class="index_status">
                        {$vo.status_str}
                      </td>
                      <td>{$vo.types_str}</td>
                      <td>{$vo.created_at}</td>
                      <td>{$vo.payed_at}</td>
                      <td>
                        <a data-toggle="modal" onClick="show({$vo.id})" data-target="#log-detail" title="查看详情" href="#">详情</a>
                        <if condition="$vo.status eq 2"> |
                          <a title="拒绝打款" href="#" data-target="#reject-withdraw" data-toggle="modal" onclick="reject(this, {$vo.id})">拒绝打款</a>
                        </if>
                        <if condition="$vo.pay_types eq 1 && $vo.status eq 2"> |
                          <a title="微信打款" href='{:U("settlements/wechat_pay", "id=$vo[id]")}'>微信打款</a>
                        </if>
                        <if condition="$vo.status eq 2"> |
                          <a title="手动打款" href="#" onclick="withdraw(this,{$vo.id})">手动打款</a>
                        </if>
                      </td>
                    </tr>
                  </volist>
                </table>
              </div>

              <ul class="pagination pull-right">
                <li>
                  <a href="{$page_list.page.first.href}" aria-label="Previous">
                      <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <li>
                  <a href="{$page_list.page.front.href}" aria-label="Previous">
                      <span aria-hidden="true">&lt;</span>
                    </a>
                </li>
                <volist name="page_list.page.list" id="plist">
                  <li <eq name="plist.index" value="1">class="active"</eq>><a href="{$plist.href}">{$plist.page}</a></li>
                </volist>
                <li>
                  <a href="{$page_list.page.after.href}" aria-label="Next">
                      <span aria-hidden="true">&gt;</span>
                    </a>
                </li>
                <li>
                  <a href="{$page_list.page.last.href}" aria-label="Next">
                      <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="modal fade" id="log-detail">

  </div>
  <div class="modal fade" id="reject-withdraw">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">拒绝提现申请</h4>
        </div>
        <div class="modal-body">
          <div class="form-box">
            <form class="form-horizontal" method="post" enctype="multipart/form-data" action="{:U('Settlements/reject')}">
              <div class="form-group">
                <label class="col-sm-2 control-label">理由</label>
                <div class="col-sm-4">
                  <textarea name="reject_reason" rows="4" cols="40"></textarea>
                </div>
              </div>
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <input type="hidden" id="withdraw_log_id" name="id" value="">
                  <input type="submit" class="btn btn-primary" value="提交">
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
    <script>
      function withdraw(obj, id) {
        var url = "{:U('settlements/withdraw')}";
        if (confirm("确认已打款给商户")) {
          $.post(url, {
            id: id
          }, function(data) {
            if (data.code != 'success') {
              alert(data.msg);
            } else {
              alert('打款成功');
              $(obj).hide();
            }
          });
        }
      }
      function inquiry(){
        document.getElementById("flag").value='';
        $('#myfrom').submit()
      }
      function flag(){
        document.getElementById("flag").value='true';
        $('#myfrom').submit()
      }
      function reject(obj, id) {
        $('#withdraw_log_id').val(id);
      }

      function show(log_id) {
        $.ajax({
          url: "{:U('settlements/show')}",
          data: {
            id: log_id
          },
          success: function(res) {
            $("#log-detail").html(res);
          }
        });
      }

      //datetimepicker
      $('#datetime-start').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        autoclose: true,
        todayBtn: true,
        language: 'zh-CN'
      });
      $('#datetime-end').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        autoclose: true,
        todayBtn: true,
        language: 'zh-CN'
      });
      $("#datetime-start").on("dp.change", function(e) {
        $('#datetime-end').data("DateTimePicker").minDate(e.date);
      });
      $("#datetime-end").on("dp.change", function(e) {
        $('#datetime-start').data("DateTimePicker").maxDate(e.date);
      });
    </script>
</body>

</html>